/*************************************************************
说明: 按键时间处理模块, 采用事件列表组织案件任务.


//Author:陈首敏
*************************************************************/

#define	APP_KEY_C

#include "Global.h"


void PowerKeyEvent(void)
{
    if(SysSet.fg.TurnOn == 0)
    {
		UserSetTurnOn();
	}
    else
    {
		UserSetTurnOff();
	}  
	SendSysSetChange(IR_CODE_TURN_ON);
}

void DownKeyEvent(void)
{
	if((SysSet.fg.TurnOn)
	&&(SysSet.Mode == MODE_COOL || SysSet.Mode == MODE_HEAT))
	{
		SysSet.Temp_C -= 10;
		if(SysSet.Temp_C < 160)SysSet.Temp_C = 160;
		SendSysSetChange(IR_CODE_DOWN);
		AbilityKeyCheck();
	}
}

void UpKeyEvent(void)
{
	if((SysSet.fg.TurnOn)
	&&(SysSet.Mode == MODE_COOL || SysSet.Mode == MODE_HEAT))
	{
		SysSet.Temp_C += 10;
		if(SysSet.Temp_C > 320)SysSet.Temp_C = 320;
		SendSysSetChange(IR_CODE_UP);
		AbilityKeyCheck();
	}
}



void FanKeyEvent(void)
{
	if((SysSet.fg.TurnOn)&&(SysSet.Mode != MODE_DRY)&&(SysSet.Mode != MODE_AUTO))
	{
		SysSet.Fan ++;
		if(SysSet.Fan > FAN_STRONG)SysSet.Fan = FAN_L;
		SendSysSetChange(IR_CODE_FAN);
	}
}

void SelfTestKeyEvent(void)
{
	if(PowerUpTime <= 30)
	{
		SysSet.fg.Test = 1;
		SysSet.fg.TurnOn = 1;
		SysSet.Mode = MODE_COOL;
		SysSet.Temp_C = 260;
		SysSet.fg.SwingUD = 1;
		SysSet.fg.SwingLF = 1;
		SendSysSetChange(IR_CODE_SELF_TEST);
	}
}

void EngineeKeyEvent(void)
{
	SendSysSetChange(IR_CODE_ENGINEE);
}

void WifiResetKeyEvent(void)
{
	SendSysSetChange(IR_CODE_WIF_RESET);
}

void KeyTest1(void)
{
	SysSet.fg.AbilityTest = 1;
	SysSet.fg.TurnOn = 1;
	SysSet.Mode = MODE_COOL;
	SysSet.Temp_C = 320;
	SendSysSetChange(IR_CODE_SWING_RL);
}

void KeyTest2(void)
{
	SendSysSetChange(IR_CODE_ECO);
}

void AppKeyInit(void)
{
	KeyPressRegist(KEY_POWER,		KEY_60MS,	0,			&PowerKeyEvent);
	KeyPressRegist(KEY_DOWN, 		KEY_60MS,	KEY_500MS,	&DownKeyEvent);
	KeyPressRegist(KEY_UP,			KEY_60MS,	KEY_500MS,	&UpKeyEvent);
	KeyPressRegist(KEY_FAN,			KEY_60MS,	0,			&FanKeyEvent);
	KeyPressRegist(KEY_SELF_TEST,	KEY_3S,		0,			&SelfTestKeyEvent);
	KeyPressRegist(KEY_ENGINEE,		KEY_3S,		0,			&EngineeKeyEvent);
	KeyPressRegist(KEY_WIFI_RESET,	KEY_3S,		0,			&WifiResetKeyEvent);

	//KeyReleaseRegist(KEY_POWER,KEY_60MS,	KEY_1S,			&KeyTest1);
}
